package cn.edu.zxj.springblog.service;

import cn.edu.zxj.springblog.mapper.BlogInfoMapper;
import cn.edu.zxj.springblog.model.BlogInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description：
 *
 * @author: zxj
 * @date: 2024-02-04
 * @time: 20:09:26
 */
@Service
@Slf4j
public class BlogInfoService {
    @Autowired
    private BlogInfoMapper blogInfoMapper;

    public List<BlogInfo> getList() {
        try {
            return blogInfoMapper.selectAll();
        } catch (Exception e) {
            log.error("查询 blog 所有信息失败, e: {}", e);
        }
        return null;
    }

    public BlogInfo getBlogDetail(Integer blogId) {
        try {
            return blogInfoMapper.selectById(blogId);
        } catch (Exception e) {
            log.error("查询 blogId: {} 详细信息失败, e: {}", blogId, e);
        }
        return null;
    }

    public Integer add(BlogInfo blogInfo) {
        try {
            return blogInfoMapper.insert(blogInfo);
        } catch (Exception e) {
            log.error("插入 blogInfo: {} 失败, e: {}", blogInfo, e);
        }
        return null;
    }

    public Integer update(BlogInfo blogInfo) {
        try {
            return blogInfoMapper.update(blogInfo);
        } catch (Exception e) {
            log.error("更新 blogInfo: {} 失败, e: {}", blogInfo, e);
        }
        return null;
    }

    public Integer delete(Integer blogId) {
        try {
            return blogInfoMapper.delete(blogId);
        } catch (Exception e) {
            log.error("删除 blogId: {} 失败, e: {}", blogId, e);
        }
        return null;
    }
}
